Skip to main content

Calculate Route

Calculate Route

Get detailed route information powered by GraphHopper routing engine. Returns comprehensive route data including path coordinates, distance, travel time, turn-by-turn instructions with street names, and elevation data (ascend/descend). Use for GPS navigation apps, route planning, delivery optimization, and mapping applications requiring detailed routing information.

Usage

import { createBarikoiClient } from "barikoiapis";

const barikoi = createBarikoiClient({
apiKey: "YOUR_BARIKOI_API_KEY",
});

const result = await barikoi.calculateRoute({
start: { latitude: 23.8103, longitude: 90.4125 },
destination: { latitude: 23.8, longitude: 90.4 },
type: "gh",
profile: "car",
});

const hints = result.data?.hints;
const paths = result.data?.paths;

Response

This API returns:

hints, info, paths (array with distance, time, points, instructions, ascend, descend)

Parameters

ParameterTypeDescription
startobjectRequired. Start coordinates with latitude and longitude
destinationobjectRequired. Destination coordinates with latitude and longitude
typestringRequired. Routing engine type: "gh" (GraphHopper)
profilestringRouting profile: "car", "motorcycle", or "bike"

Example with Turn-by-Turn Instructions

const result = await barikoi.calculateRoute({
start: { latitude: 23.8103, longitude: 90.4125 },
destination: { latitude: 23.8, longitude: 90.4 },
type: "gh",
profile: "car",
});

const path = result.data?.paths?.[0];

if (path) {
console.log(`Distance: ${(path.distance / 1000).toFixed(2)} km`);
console.log(`Time: ${(path.time / 60000).toFixed(0)} minutes`);
console.log(`Elevation gain: ${path.ascend}m`);
console.log(`Elevation loss: ${path.descend}m`);

// Turn-by-turn instructions
path.instructions?.forEach((instruction, index) => {
console.log(`${index + 1}. ${instruction.text} (${instruction.distance}m)`);
});
}
Type Definitions
export type CalculateRouteParams = {
start: { latitude: number; longitude: number };
destination: { latitude: number; longitude: number };
type: "gh";
profile?: "car" | "motorcycle" | "bike";
};

export type CalculateRouteSuccess = {
hints?: {
"visited_nodes.sum"?: number;
"visited_nodes.average"?: number;
};
info?: {
copyrights?: Array<string>;
took?: number;
road_data_timestamp?: string;
};
paths?: Array<{
/**
* Distance in meters
*/
distance?: number;
weight?: number;
/**
* Time in milliseconds
*/
time?: number;
transfers?: number;
points_encoded?: boolean;
bbox?: [number, number, number, number];
/**
* GeoJSON LineString with route coordinates
*/
points?: {
type?: "LineString";
coordinates?: Array<[number, number]>;
};
instructions?: Array<{
distance?: number;
heading?: number;
sign?: number;
interval?: [number, number];
text?: string;
time?: number;
street_name?: string;
}>;
legs?: Array<unknown>;
details?: Array<unknown>;
ascend?: number;
descend?: number;
snapped_waypoints?: {
type?: "LineString";
coordinates?: Array<[number, number]>;
};
}>;
};